#ifndef _RKNN_YOLOV5_DEMO_POSTPROCESS_H_
#define _RKNN_YOLOV5_DEMO_POSTPROCESS_H_

#include <stdint.h>
#include <vector>
#include "common.h"
#include "rknn_api.h"
#define OBJ_NAME_MAX_SIZE 16
#define OBJ_NUMB_MAX_SIZE 64
#define OBJ_CLASS_NUM 9
#define LABEL_NALE_TXT_PATH "./../../model/coco_5_labels_list.txt"

//80
#define NMS_THRESH 0.8
#define BOX_THRESH 0.7
#define PROP_BOX_SIZE (5 + OBJ_CLASS_NUM)

#define PROTO_CHANNEL 32
#define PROTO_HEIGHT 160
#define PROTO_WEIGHT 160

#define N_CLASS_COLORS 20

typedef struct _BOX_RECT
{
    int left;
    int right;
    int top;
    int bottom;
} BOX_RECT;
typedef struct {
    rknn_context rknn_ctx;
    rknn_input_output_num io_num;
    rknn_tensor_attr* input_attrs;
    rknn_tensor_attr* output_attrs;
    int model_channel;
    int model_width;
    int model_height;
    int input_image_width;
    int input_image_height;
    bool is_quant;
} rknn_app_context_t;
typedef struct __detect_result_t
{
    int class_id;
    char name[OBJ_NAME_MAX_SIZE];
    BOX_RECT box;
    float prop;
} detect_result_t;

typedef struct _detect_result_group_t
{
    int id;
    int count;
    detect_result_t results[OBJ_NUMB_MAX_SIZE];
} detect_result_group_t;
typedef struct
{
    image_rect_t box;
    float prop;
    int cls_id;
} object_detect_result;

typedef struct
{
    uint8_t *seg_mask;
    uint32_t pixel_cnt;
} object_segment_result;
typedef struct
{
    int id;
    int count=0;
    object_detect_result results[OBJ_NUMB_MAX_SIZE];
    object_segment_result results_seg[OBJ_NUMB_MAX_SIZE];
} object_detect_result_list;
// int post_process(int8_t *input0, int8_t *input1, int8_t *input2, int model_in_h, int model_in_w,
//                  float conf_threshold, float nms_threshold, BOX_RECT pads, float scale_w, float scale_h,
//                  std::vector<int32_t> &qnt_zps, std::vector<float> &qnt_scales,
//                  detect_result_group_t *group);
// int post_process(rknn_app_context_t *app_ctx, void *outputs, letterbox_t *letter_box, float conf_threshold, float nms_threshold, detect_result_group_t *od_results);
int post_process(rknn_app_context_t *app_ctx, rknn_output *outputs, letterbox_t *letter_box, float conf_threshold, float nms_threshold, object_detect_result_list *od_results);
int loadLabelName(const char *locationFilename, char *label[]);
int clamp(float val, int min, int max);
#endif //_RKNN_YOLOV5_DEMO_POSTPROCESS_H_
